package com.filldream.sun.bean.result;

/**
 * 错误码枚举类
 * 只提供大的错误类型，可自定义错误信息
 * @author RickSun
 * 2019-03-22 15:56
 */
public enum ErrorCode {

    SUCCESS(0,"ok.","成功"),
    EMPTY_RESULT(0,"Ok,But empty","成功"),
    FAIL(-1,"fail.","失败"),
    SERVER_BUSY(-2,"The system is busy. Please try again later.","系统繁忙，请稍后再试"),
    PAY_ERR(-1000,"Pay failed, please check.","支付错误，请检查参数或配置"),
    NO_LOGIN(-1001,"Login failed, please re-login.","登陆验证失败，请重新登陆"),
    OVER_TIME(-1002,"Server timeout.","超时"),
    PARAM_ERR(-1003,"Parameter error.","参数错误%s"),
    METHOD_ERR(-1004,"Method error.","方法错误"),
    DBD_ERR(-1005,"Data exception in database.","数据库数据异常"),
    DB_ERR(-1006,"Database exception.","数据库异常"),
    CONN_ERR(-1007,"Connection error.","连接异常"),
    SIZE_ERR(-1008,"Size error.","大小异常"),
    RANGE_ERR(-1009,"Range error.","范围异常"),
    BUSINESS_ERR(-1010,"Business error.","业务异常"),
    INVALID_ERR(-1011,"Field invalid","输入非法参数:%s"),
    AUTH_ERR(-99999,"Authentication failure.","鉴权异常"),
    //next is example

    //HTTP错误100000+
    HTTPSTATUSFAIL(100000,"Http Status IS NOT SC_OK.","HTTP请求状态错误"),
    HTTPREQUESTFAIL(100001,"Http Request fail.","HTTP请求错误%s"),

    ;

    /** 错误码  */
    private int code;

    /** 返回信息  */
    private String msg;

    /**
     * 填充
     */
    private String content;


    /** 返回信息  */
    private String enmsg;

    private ErrorCode(int code, String enmsg,String msg){
        this.code = code ;
        this.msg = msg ;
        this.enmsg =enmsg;
    }


    ErrorCode(String msg){
        this.code = -1010;
        this.msg = msg;
        this.enmsg = "Business error.";
    }

    public ErrorCode setContent(String content) {
        this.content = content;
        return this;
    }



    //getter and setter
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

//    public String getMsg() {
//        return msg;
//    }

    public String getMsg() {
        if (this.content != null) {
            return msg.replace("%s", content);
        } else {
            return msg.replace("%s", "").replace("()", "");
        }
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getEnmsg() {
        return enmsg;
    }

    public void setEnmsg(String enmsg) {
        this.enmsg = enmsg;
    }}
